const fs = require('fs')
const { promisify } = require('util')

const readFile = promisify(fs.readFile) // fs.readFile 改成 promise, 入参不变
const writeFile = promisify(fs.writeFile) // 写文件操作 promise 化

exports.getDb = async (filePath) => {
	const data = await readFile(filePath, 'utf8')
	return JSON.parse(data)
}

exports.serveDb = async (filePath, data) => {
	data = JSON.stringify(data)
	return await writeFile(filePath, data)
}

// exports.
